<?php $i_hm = 0; ?>
<?php $i_bht = 0; ?>
<form method="post" action="<?php echo base_path() . 'san_pham/ban_hang/lap_phieu_ban_hang' ?>" id="lap-phieu-ban-hang"
      class="lap-phieu-ban-hang">
<div class="form-item form-text-wrapper khach-hang-wrapper">
  <label for="txt-khach-hang">Khách hàng</label>
  <input id="txt-khach-hang" value="<?php echo ($_POST && $_POST['khach-hang']) ? $_POST['khach-hang'] : '' ?>"
         name="khach-hang" type="text"
         class="form-text form-autocomplete text txt-khach-hang" autocomplete="OFF"/>
  <input class="autocomplete" type="hidden" id="txt-khach-hang-autocomplete"
         value="<?php echo base_path() . 'khach_hang/autocomplete' ?>" disabled="disabled"/>
  <input id="load-data-khach-hang" type="button" value="Lấy dữ liệu" class="form-submit"/>
  <span id="load-data-khach-hang-img"></span>
</div>
<div class="clear"></div>
<div id="load-data-khach-hang-wrapper">
  <?php
        if ($_POST) {
  echo '<div class="form-item form-text-wrapper loai-khach-hang-wrapper">
                <label>Loại khách hàng:</label>
                <label id="lbl-loai-khach-hang" class="data-text">' . ($_POST['txt_loai_khach_hang'] ? 'đặc biệt'
    : 'bình thường') . '<input type="hidden" id="txt-ma-khach-hang" name="txt_ma_khach_hang" value="' . $_POST['txt_ma_khach_hang'] . '" /><input type="hidden" id="txt-loai-khach-hang" name="txt_loai_khach_hang" value="' . $_POST['txt_loai_khach_hang'] . '" /></label>
              </div>
              <div class="form-item form-text-wrapper no-khach-hang-wrapper">
                <label>Số tiền nợ:</label>
                <label id="lbl-no-khach-hang" class="data-text">' . number_format($_POST['txt_tien_no']) . '<input type="hidden" name="txt_tien_no" value="' . $_POST['txt_tien_no'] . '" /></label>
              </div>
              <div class="clear"></div>';
}
  ?>
</div>
<div id="load-data-tong-khuyen-mai-wrapper">
  <?php
        if ($_POST) {
    $header = array('Tên', 'Số lượng','Đơn giá','Thành tiền');
    $header1 = array('Tên', 'Số lượng','Đầu khuyến mãi','Khuyến mãi','Đơn giá','Thành tiền');
  $ma_khach = $_POST['txt_ma_khach_hang'];
  $loai_khach = get_khach_hang_theo_ma($ma_khach)->loai;
  $so_luong_mua = $_POST['txt_so_luong_mua'];
  $arr_so_luong = explode(',', $so_luong_mua);
  $ma_hang = $_POST['txt_ma_hang_mua'];
  $arr_ma = explode(',', $ma_hang);
  $tong_thang = get_tong_thang($arr_ma,$arr_so_luong,$ma_khach,0,$loai_khach);
  $tong_km = get_tong_km_thang($ma_khach,0);
  echo '<div class="form-item form-text-wrapper tong-mua-thang-wrapper">
                    <label>Tổng mua trong tháng:</label>
                    <label id="lbl-tong-mua-thang" class="data-text"><a href="javascript:;" onclick="tong_thang()">'.number_format($_POST['txt_tong_mua_thang']).'</a><input type="hidden" id="txt-loai-khach-hang" name="txt_tong_mua_thang" value="' . $_POST['txt_tong_mua_thang'] . '" /></label>
        </div>
        <div class="form-item form-text-wrapper tong-tien-km-thang-wrapper">
                    <label>Được khuyến mại:</label>
                    <label id="lbl-tong-tien-km-thang" class="data-text"><a href="javascript:;" onclick="tong_thang()">'.number_format($_POST['txt_tong_km_thang']).'</a><input type="hidden" id="txt-loai-khach-hang" name="txt_tong_km_thang" value="' . $_POST['txt_tong_km_thang'] . '" /></label>
        </div>
        <div class="form-item form-text-wrapper da-km-thang-wrapper">
                    <label>Đã khuyến mại trong tháng:</label>
                    <label id="lbl-tong-km-thang" class="data-text"><a href="javascript:;" onclick="tong_km_thang()">'.number_format($_POST['txt_da_km_thang']).'</a><input type="hidden" name="txt_da_km_thang" value="' . $_POST['txt_da_km_thang']. '" /></label>
        </div>
        <div class="form-item form-text-wrapper da-km-thang-wrapper">
                    <label>Số dư khuyến mại đầu tháng:</label>
                    <label id="lbl-du-km" class="data-text">'.number_format($_POST['txt_du_km']).'<input type="hidden" name="txt_du_km" value="' . ($_POST['txt_du_km']). '" /></label>
        </div>
        <div class="form-item form-text-wrapper duoc-km-wrapper">
                    <label>Còn lại:</label>
                    <label id="lbl-duoc-km" class="data-text">'.number_format($_POST['txt_duoc_km']).'<input type="hidden" name="txt_duoc_km" value="' . ($_POST['txt_duoc_km']). '" /></label>
        </div>
         <div class="clear"></div><div id="tong-thang-dialog" style="display: none;">'.theme('table', array('header' => $header1, 'rows' => $tong_thang)).'</div>
         <div id="tong-km-thang-dialog" style="display: none;">'.theme('table', array('header' => $header, 'rows' => $tong_km)).'
         <input type="hidden"  name="txt_ma_khach_hang" value="' . $ma_khach . '" />
         <input type="hidden"  name="txt_so_luong_mua" value="' . $so_luong_mua . '" />
         <input type="hidden"  name="txt_ma_hang_mua" value="' . $ma_hang . '" /></div>';
  }
  ?>
</div>
<fieldset>
  <legend>Nhập hàng bán</legend>
  <div id="form-item-hang-mua-wrapper">
  <?php
          $header_ban = array(
    'Tên sản phẩm',
    'Số lượng',
    'Hủy bỏ',
    'Kiểm tra SL',
    'Đơn giá',
    'Thành tiền',
    'Số lượng KM',
    'Trừ tiền'
  );
    $rows_ban = array();
    if ($_POST && isset($_POST['ten_hang_mua'])) {
      foreach ($_POST['ten_hang_mua'] as $key => $ten_hang_mua) {
        $i_hm++;
        $str_atc = '';
        if ($i_hm > 1) {
          $str_atc = '<input class="autocomplete" type="hidden" id="txt-ten-hang-mua-' . $i_hm . '-autocomplete" value="' . base_path() . 'san_pham/autocomplete" disabled="disabled"/>';
        }
        $rows_ban[] = array(
          '<input id="txt-ten-hang-mua-' . $i_hm . '" value="' . $ten_hang_mua . '" name="ten_hang_mua[' . $i_hm . ']" type="text" class="form-text form-autocomplete text txt-ten-hang-mua ' . (($_POST['error']['key'] == $key && isset($_POST['error']['ten_hang_mua']))
            ? 'error' : '') . '" autocomplete="OFF"/>' . $str_atc,
          '<input id="txt-so-luong-hang-mua-' . $i_hm . '" value="' . $_POST['so_luong_hang_mua'][$key] . '" name="so_luong_hang_mua[' . $i_hm . ']" type="text" class="form-text text txt-so-luong-hang-mua ' . (($_POST['error']['key'] == $key && isset($_POST['error']['so_luong_hang_mua']))
            ? 'error' : '') . '" autocomplete="OFF"/>',
          '<input id="field-remove-hang-mua-submit-' . $i_hm . '" type="button" value="X" class="field-remove-submit form-submit"/>',
          '<label id="lbl-kiem-tra-so-luong-' . $i_hm . '" class="data-text">' . $_POST['kiem_tra_so_luong'][$key] . '</label><input type="hidden" class="txt-hidden" id="txt-kiem-tra-so-luong-' . $i_hm . '" name="kiem_tra_so_luong[' . $i_hm . ']" value="' . $_POST['kiem_tra_so_luong'][$key] . '" />',
          '<label id="lbl-don-gia-hang-mua-' . $i_hm . '" class="data-text">' . number_format($_POST['don_gia_hang_mua'][$key]) . '</label><input type="hidden" class="txt-hidden" id="txt-don-gia-hang-mua-' . $i_hm . '" name="don_gia_hang_mua[' . $i_hm . ']" value="' . $_POST['don_gia_hang_mua'][$key] . '" />',
          '<label id="lbl-thanh-tien-hang-mua-' . $i_hm . '" class="data-text">' . number_format($_POST['thanh_tien_hang_mua'][$key]) . '</label><input type="hidden" class="txt-hidden" id="txt-thanh-tien-hang-mua-' . $i_hm . '" name="thanh_tien_hang_mua[' . $i_hm . ']" value="' . $_POST['thanh_tien_hang_mua'][$key] . '" />',
          '<input id="txt-so-luong-khuyen-mai-' . $i_hm . '" value="' . $_POST['so_luong_khuyen_mai'][$key] . '" name="so_luong_khuyen_mai[' . $i_hm . ']" type="text" class="form-text text txt-so-luong-khuyen-mai ' . (($_POST['error']['key'] == $key && isset($_POST['error']['so_luong_khuyen_mai']))
            ? 'error' : '') . '" autocomplete="OFF"/>',
          '<input type="checkbox" ' . ((isset($_POST['tru_tien_khuyen_mai']) && isset($_POST['tru_tien_khuyen_mai'][$key]))
            ? 'checked="checked"'
            : '') . ' name="tru_tien_khuyen_mai[' . $i_hm . ']" class="form-checkbox checkbox chk-tru-tien-khuyen-mai tru-tien" value="' . $i_hm . '" />'
        );
      }
    }
    else {
      $i_hm++;
      $rows_ban[] = array(
        '<input id="txt-ten-hang-mua-1" name="ten_hang_mua[1]" type="text" class="form-text form-autocomplete text txt-ten-hang-mua" autocomplete="OFF"/>',
        '<input id="txt-so-luong-hang-mua-1" name="so_luong_hang_mua[1]" type="text" class="form-text text txt-so-luong-hang-mua" autocomplete="OFF"/>',
        '<input id="field-remove-hang-mua-submit-1" type="button" value="X" class="field-remove-submit form-submit"/>',
        '<label id="lbl-kiem-tra-so-luong-1" class="data-text"></label><input type="hidden" class="txt-hidden" id="txt-kiem-tra-so-luong-1" name="kiem_tra_so_luong[1]" value="" />',
        '<label id="lbl-don-gia-hang-mua-1" class="data-text"></label><input type="hidden" class="txt-hidden" id="txt-don-gia-hang-mua-1" name="don_gia_hang_mua[1]" value="" />',
        '<label id="lbl-thanh-tien-hang-mua-1" class="data-text"></label><input type="hidden" class="txt-hidden" id="txt-thanh-tien-hang-mua-1" name="thanh_tien_hang_mua[1]" value="" />',
        '<input id="txt-so-luong-khuyen-mai-1" name="so_luong_khuyen_mai[1]" type="text" class="form-text text txt-so-luong-khuyen-mai" autocomplete="OFF"/>',
        '<input type="checkbox" name="tru_tien_khuyen_mai[1]" class="form-checkbox checkbox chk-tru-tien-khuyen-mai tru-tien" value="1" />'
      );
    }
    echo theme('table', array('header' => $header_ban, 'rows' => $rows_ban));
    ?>
  </div>
  <div id="add-more-hang-mua-wrapper">
    <input id="add-more-hang-mua" type="button" value="Thêm sản phẩm" class="field-add-more-submit form-submit"/>
    <input id="load-data-khuyen-mai" type="button" value="Lấy dữ liệu khuyến mại"
           class="field-load-data-khuyen-mai form-submit"/>
  </div>
</fieldset>

<fieldset id="hbht-fs">
  <legend>Hàng bảo hành trước (chưa nhập hàng hồi)</legend>
  <div id="form-item-bao-hanh-truoc-wrapper">
  <?php
          $header_bht = array(
    'Tên sản phẩm',
    'Số lượng',
    'Hủy bỏ'
  );
    $rows_bht = array();
    if ($_POST && isset($_POST['ten_hang_bao_hanh_truoc'])) {
      foreach ($_POST['ten_hang_bao_hanh_truoc'] as $key => $ten_hang_bao_hanh_truoc) {
        $i_bht++;
        $str_atc = '';
        if ($i_bht > 1) {
          $str_atc = '<input class="autocomplete" type="hidden" id="txt-ten-hang-bao-hanh-truoc-' . $i_bht . '-autocomplete" value="' . base_path() . 'san_pham/autocomplete" disabled="disabled"/>';
        }
        $rows_bht[] = array(
          '<input id="txt-ten-hang-bao-hanh-truoc-' . $i_bht . '" value="' . $ten_hang_bao_hanh_truoc . '" name="ten_hang_bao_hanh_truoc[]" type="text" class="form-text form-autocomplete text txt-ten-hang-bao-hanh-truoc ' . (($_POST['error']['key'] == $key && isset($_POST['error']['ten_hang_bao_hanh_truoc']))
            ? 'error' : '') . '" autocomplete="OFF"/>',
          '<input id="txt-so-luong-hang-bao-hanh-truoc-' . $i_bht . '" value="' . $_POST['so_luong_hang_bao_hanh_truoc'][$key] . '" name="so_luong_hang_bao_hanh_truoc[]" type="text" class="form-text text txt-so-luong-hang-bao-hanh-truoc ' . (($_POST['error']['key'] == $key && isset($_POST['error']['so_luong_hang_bao_hanh_truoc']))
            ? 'error' : '') . '" autocomplete="OFF"/>',
          '<input id="field-remove-hang-bao-hanh-truoc-submit-' . $i_bht . '" type="button" value="X" class="field-remove-submit form-submit"/>'
        );
      }
    }
    else {
      $i_bht++;
      $rows_bht[] = array(
        '<input id="txt-ten-hang-bao-hanh-truoc-1" name="ten_hang_bao_hanh_truoc[]" type="text" class="form-text form-autocomplete text txt-ten-hang-bao-hanh-truoc" autocomplete="OFF"/>',
        '<input id="txt-so-luong-hang-bao-hanh-truoc-1" name="so_luong_hang_bao_hanh_truoc[]" type="text" class="form-text text txt-so-luong-hang-bao-hanh-truoc" autocomplete="OFF"/>',
        '<input id="field-remove-hang-bao-hanh-truoc-submit-1" type="button" value="X" class="field-remove-submit form-submit"/>'
      );
    }
    echo theme('table', array('header' => $header_bht, 'rows' => $rows_bht));
    ?>
  </div>
  <div id="add-more-hang-bao-hanh-truoc-wrapper">
    <input id="add-more-bao-hanh-truoc" type="button" value="Thêm bảo hành" class="field-add-more-submit form-submit"/>
  </div>
</fieldset>

<fieldset
  id="hdbh-fs" <?php if ($_POST && isset($_POST['don_gia_tru_tien_hang_duoc_bao_hanh'])) { ?>style="display: block;" <?php } ?>>
  <legend>Hàng được bảo hành (đã nhập hàng hồi)</legend>
  <div id="form-item-hang-duoc-bao-hanh-wrapper">
  <?php
          if ($_POST && isset($_POST['don_gia_tru_tien_hang_duoc_bao_hanh'])) {
    $header_dbh = array(
      'Trả hàng',
      'Mã phiếu hồi',
      'Tên sản phẩm',
      'Mang đến',
      'Được bảo hành',
      'Đơn giá',
      'Trừ tiền'
    );
    $rows_dbh = array();
    foreach ($_POST['don_gia_tru_tien_hang_duoc_bao_hanh'] as $id => $don_gia_tru_tien_hang_duoc_bao_hanh) {
      $rows_dbh[] = array(
        '<input type="checkbox" ' . ((isset($_POST['tra_hang_duoc_bao_hanh']) && isset($_POST['tra_hang_duoc_bao_hanh'][$id]))
          ? 'checked="checked"'
          : '') . ' name="tra_hang_duoc_bao_hanh[' . $id . ']" class="form-checkbox checkbox txt-tra-hang-duoc-bao-hanh tra-hang tra-hang-' . $_POST['mp_hang_duoc_bao_hanh'][$id] . '" value="' . $_POST['mp_hang_duoc_bao_hanh'][$id] . '" />',
        '<label class="data-text ma-phieu-hang-hoi">' . $_POST['mp_hang_duoc_bao_hanh'][$id] . '</label>',
        '<label class="data-text ten-hang-duoc-bao-hanh">' . $_POST['ten_thanh_pham_hang_duoc_bao_hanh'][$id] . '</label>',
        '<label class="data-text so-luong-hang-mang-den">' . $_POST['so_luong_hang_mang_den'][$id] . '</label>',
        '<label class="data-text so-luong-hang-duoc-bao-hanh">' . $_POST['so_luong_hang_duoc_bao_hanh'][$id] . '</label>',
        '<label class="data-text lbl-don-gia-hang-duoc-bao-hanh">' . number_format($_POST['gia_tien_hang_duoc_bao_hanh'][$id]) . '</label>',
        '<input type="checkbox" ' . ((isset($_POST['tru_tien_hang_duoc_bao_hanh']) && isset($_POST['tru_tien_hang_duoc_bao_hanh'][$id]))
          ? 'checked="checked"'
          : '') . ' name="tru_tien_hang_duoc_bao_hanh[' . $id . ']" class="form-checkbox checkbox txt-tru-tien-hang-duoc-bao-hanh tru-tien" value="' . $_POST['ma_hang_duoc_bao_hanh'][$id] . '" />
              <input type="text" name="don_gia_tru_tien_hang_duoc_bao_hanh[' . $id . ']" class="form-text text txt-don-gia-tru-tien-hang-duoc-bao-hanh format-currency ' . (($_POST['error']['key'] == $id && isset($_POST['error']['don_gia_tru_tien_hang_duoc_bao_hanh']))
          ? 'error' : '') . '" autocomplete="OFF" value="' . $don_gia_tru_tien_hang_duoc_bao_hanh . '" />
              <input type="hidden" name="ten_thanh_pham_hang_duoc_bao_hanh[' . $id . ']" value="' . $_POST['ten_thanh_pham_hang_duoc_bao_hanh'][$id] . '" />
              <input type="hidden" name="gia_tien_hang_duoc_bao_hanh[' . $id . ']" value="' . $_POST['gia_tien_hang_duoc_bao_hanh'][$id] . '" />
              <input type="hidden" name="so_luong_hang_mang_den[' . $id . ']" value="' . $_POST['so_luong_hang_mang_den'][$id] . '" />
              <input type="hidden" name="so_luong_hang_duoc_bao_hanh[' . $id . ']" value="' . $_POST['so_luong_hang_duoc_bao_hanh'][$id] . '" />
              <input type="hidden" name="ma_hang_duoc_bao_hanh[' . $id . ']" value="' . $_POST['ma_hang_duoc_bao_hanh'][$id] . '" />
              <input type="hidden" name="mp_hang_duoc_bao_hanh[' . $id . ']" value="' . $_POST['mp_hang_duoc_bao_hanh'][$id] . '" />'
      );
    }
    echo theme('table', array('header' => $header_dbh, 'rows' => $rows_dbh));
    echo (($_POST['ghi_chu_duoc_bao_hanh'])
      ? '<div id="ghi-chu-hang-duoc-bao-hanh">' . $_POST['ghi_chu_duoc_bao_hanh'] . '</div>' : '');
  }
    ?>
  </div>
</fieldset>

<fieldset
  id="hnc-fs" <?php if ($_POST && isset($_POST['don_gia_tru_tien_hang_no_cu'])) { ?>style="display: block;" <?php } ?>>
  <legend>Hàng nợ cũ</legend>
  <div id="form-item-hang-no-cu-wrapper">
  <?php
          if ($_POST && isset($_POST['don_gia_tru_tien_hang_no_cu'])) {
    $header_hnc = array(
      'Tên sản phẩm',
      'Số lượng',
      'Đơn giá',
      'Trừ tiền'
    );
    $rows_hnc = array();
    foreach ($_POST['don_gia_tru_tien_hang_no_cu'] as $ma_thanh_pham => $don_gia_tru_tien_hang_no_cu) {
      $rows_hnc[] = array(
        '<label class="data-text ten-hang-no-cu">' . $_POST['ten_thanh_pham_hang_no_cu'][$ma_thanh_pham] . '</label>',
        '<label class="data-text so-luong-hang-no-cu">' . $_POST['so_luong_hang_no_cu'][$ma_thanh_pham] . '</label>',
        '<label class="data-text lbl-don-gia-hang-no-cu">' . number_format($_POST['gia_tien_hang_no_cu'][$ma_thanh_pham]) . '</label>',
        '<input type="checkbox" ' . ((isset($_POST['tru_tien_hang_no_cu']) && isset($_POST['tru_tien_hang_no_cu'][$ma_thanh_pham]))
          ? 'checked="checked"'
          : '') . ' name="tru_tien_hang_no_cu[' . $ma_thanh_pham . ']" class="form-checkbox checkbox txt-tru-tien-hang-no-cu tru-tien" value="' . $ma_thanh_pham . '" />
              <input type="text" name="don_gia_tru_tien_hang_no_cu[' . $ma_thanh_pham . ']" class="form-text text txt-don-gia-tru-tien-hang-no-cu format-currency ' . (($_POST['error']['key'] == $ma_thanh_pham && isset($_POST['error']['don_gia_tru_tien_hang_no_cu']))
          ? 'error' : '') . '" autocomplete="OFF" value="' . $don_gia_tru_tien_hang_no_cu . '" />
              <input type="hidden" name="ten_thanh_pham_hang_no_cu[' . $ma_thanh_pham . ']" value="' . $_POST['ten_thanh_pham_hang_no_cu'][$ma_thanh_pham] . '" />
              <input type="hidden" name="gia_tien_hang_no_cu[' . $ma_thanh_pham . ']" value="' . $_POST['gia_tien_hang_no_cu'][$ma_thanh_pham] . '" />
              <input type="hidden" name="so_luong_hang_no_cu[' . $ma_thanh_pham . ']" value="' . $_POST['so_luong_hang_no_cu'][$ma_thanh_pham] . '" />'
      );
    }
    echo theme('table', array('header' => $header_hnc, 'rows' => $rows_hnc));
  }
    ?>
  </div>
</fieldset>

<fieldset
  id="hnbht-fs" <?php if ($_POST && isset($_POST['ten_thanh_pham_hang_no_bht'])) { ?>style="display: block;" <?php } ?>>
  <legend>Khách hàng nợ hàng bảo hành trước (số lượng nợ được trừ trong đơn hàng này nếu có mặt hàng xuất đó kho)
  </legend>
  <div id="form-item-hang-no-bht-wrapper">
  <?php
          if ($_POST && isset($_POST['don_gia_tru_tien_hang_duoc_bao_hanh'])) {
    $header_no_bht = array(
      'Mã phiếu bán hàng',
      'Tên sản phẩm',
      'Mang đi',
      'Nhận lại',
      'Không được bảo hành',
      'Đã trả'
    );
    $rows_no_bht = array();
    foreach ($_POST['ten_thanh_pham_hang_no_bht'] as $id => $ten_thanh_pham_hang_no_bht) {
      $rows_no_bht[] = array(
        '<label class="data-text ma-phieu-ban-hang">' . $_POST['mp_hang_no_bht'][$id] . '</label>',
        '<label class="data-text ten-hang-no-bht">' . $ten_thanh_pham_hang_no_bht . '</label>',
        '<label class="data-text so-luong-hang-mang-di">' . $_POST['so_luong_hang_mang_di'][$id] . '</label>',
        '<label class="data-text so-luong-hang-nhan-lai">' . $_POST['so_luong_hang_nhan_lai'][$id] . '</label>',
        '<label class="data-text so-luong-hang-khong-duoc-bao-hanh">' . $_POST['so_luong_hang_khong_duoc_bao_hanh'][$id] . '</label>',
        '<label class="data-text so-luong-hang-tra-no">' . $_POST['so_luong_hang_tra_no'][$id] . '</label>
              <input type="hidden" name="ten_thanh_pham_hang_no_bht[' . $id . ']" value="' . $ten_thanh_pham_hang_no_bht . '" />
              <input type="hidden" name="so_luong_hang_mang_di[' . $id . ']" value="' . $_POST['so_luong_hang_mang_di'][$id] . '" />
              <input type="hidden" name="so_luong_hang_nhan_lai[' . $id . ']" value="' . $_POST['so_luong_hang_nhan_lai'][$id] . '" />
              <input type="hidden" name="so_luong_hang_khong_duoc_bao_hanh[' . $id . ']" value="' . $_POST['so_luong_hang_khong_duoc_bao_hanh'][$id] . '" />
              <input type="hidden" name="so_luong_hang_tra_no[' . $id . ']" value="' . $_POST['so_luong_hang_tra_no'][$id] . '" />
              <input type="hidden" name="so_luong_hang_dang_no[' . $id . ']" value="' . $_POST['so_luong_hang_dang_no'][$id] . '" />
              <input type="hidden" name="ma_hang_no_bht[' . $id . ']" value="' . $_POST['ma_hang_no_bht'][$id] . '" />
              <input type="hidden" name="mp_hang_no_bht[' . $id . ']" value="' . $_POST['mp_hang_no_bht'][$id] . '" />'
      );
    }
    echo theme('table', array('header' => $header_no_bht, 'rows' => $rows_no_bht));
    echo (($_POST['ghi_chu_hang_no_bht']) ? '<div id="ghi-chu-hang-no-bht">' . $_POST['ghi_chu_hang_no_bht'] . '</div>'
      : '');
  }
    ?>
  </div>
</fieldset>

<div class="form-item form-textarea-wrapper">
  <label for="ghi-chu">Ghi chú</label>
  <textarea id="ghi-chu" name="ghi_chu"
            class="form-textarea <?php echo ($_POST && (string) $_POST['error']['key'] == 'ghi_chu') ? 'error' : '' ?>"
            cols="60" rows="5"><?php echo ($_POST) ? $_POST['ghi_chu'] : '' ?></textarea>

  <div class="description">Nhập tối đa 500 ký tự. Số lượng hiện thời: <span style="color: red;"
                                                                            id="ghi-chu-length">0</span></div>
</div>
<div id="submit-wrapper">
  <input class="autocomplete" type="hidden" id="txt-ten-hang-mua-1-autocomplete"
         value="<?php echo base_path() . 'san_pham/autocomplete' ?>" disabled="disabled"/>
  <input class="autocomplete" type="hidden" id="txt-ten-hang-bao-hanh-truoc-1-autocomplete"
         value="<?php echo base_path() . 'san_pham/autocomplete' ?>" disabled="disabled"/>
  <input type="hidden" id="total-hang-mua" value="<?php echo $i_hm  ?>" disabled="disabled"/>
  <input type="hidden" id="total-hang-bao-hanh-truoc" value="<?php echo $i_bht  ?>" disabled="disabled"/>
  <input id="submit" type="submit" onclick="return check_lap_phieu();" value="Nhập dữ liệu" class="form-submit"/>
<!--  <input id="submit" type="submit" value="Nhập dữ liệu" class="form-submit" style="display: none;"/>-->
</div>
</form>